package com.binguo.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.binguo.api.form.LoginForm;
import com.binguo.api.form.ShopConfigForm;
import com.binguo.api.result.Result;
import com.binguo.api.result.ResultGenerator;
import com.binguo.model.api.vo.EmployeeVO;
import com.binguo.model.model.Shop;
import com.binguo.model.model.ShopConfig;
import com.binguo.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

/**
 * @author yuritian
 * @Title: ShopController
 * @ProjectName binguoDevelop
 * @Description: TODO
 * @date 2020/6/2710:55
 */
@Api(tags = "商户配置")
@RestController
@RequestMapping
public class ShopController {

    @Resource
    ShopService shopService;

    @PostMapping(value = "/api/shop/getShopConfig", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取登陆页面收营员列表", notes = "通过商户id,测试shopId＝2")
    public Result getShopConfig(@RequestBody @Valid ShopConfigForm form) {

         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        List<ShopConfig> configList = shopService.getShopList(form.getShopId(),form.getBranchId(),form.getCashierDeskId(),form.getParamName());
        JSONObject result = new JSONObject();

        JSONArray configArray = new JSONArray();

        for (ShopConfig config : configList){
            JSONObject configObject = new JSONObject();
            configObject.put("shopId",config.getShopId());
            configObject.put("cashierDeskId",config.getCashierDeskId());
            configObject.put("paramName",config.getParamName());
            configObject.put("paramValue",config.getParamValue());
            configObject.put("description",config.getDescription());
            configObject.put("remark",config.getRemark());
            configObject.put("createDtme",dateFormat.format(config.getCreateDtme()));
            configObject.put("lastUpdtme",dateFormat.format(config.getLastUpdtme()));
            configArray.add(configObject);
        }

        result.put("configList",configArray);

        return ResultGenerator.genSuccessResult(result);
    }
}
